/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils.workspace;

import javax.swing.JFileChooser;
import utils.properties.YourJavaPropertiesUtils;
import views.FirstFrame;

/**
 *
 * @author Juan.Garcia
 */
public class WorkspaceSelectorUtils {
    
    public WorkspaceSelectorUtils(){
        
        
    }
    
    /**
     * Select the new workspace and update the file .properties with the new workspace 
     * 
     * @return void
     */
    public static void select(){
        
           JFileChooser workspaceSelector = new JFileChooser("Selecciona el nuevo Workspace");
           
           workspaceSelector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
           
           int returnVal = workspaceSelector.showOpenDialog(null);
           
           if (returnVal == JFileChooser.APPROVE_OPTION){
               
               String workspace = workspaceSelector.getSelectedFile().getAbsolutePath();
               
               YourJavaPropertiesUtils.setProperty("workspace",workspace,"properties");
               
               FirstFrame wnd = new FirstFrame(workspace);
               
           }else{
               
               FirstFrame wnd = new FirstFrame("C:/");
               
           }  
        
    }
    
    
     /**
     * Select the new workspace and update the file .properties with the new workspace 
     * 
     * @return String returns the selected workspace
     */
    public static String selectAndReturnWorkspace(int config){
        
           String workspace = "";
        
           JFileChooser workspaceSelector = new JFileChooser("Selecciona el nuevo Workspace");
           
           workspaceSelector.setFileSelectionMode(config);
           
           int returnVal = workspaceSelector.showOpenDialog(null);
           
           if (returnVal == JFileChooser.APPROVE_OPTION){
               
               workspace = workspaceSelector.getSelectedFile().getAbsolutePath();
               
               YourJavaPropertiesUtils.setProperty("workspace",workspace,"properties");
               
              
           }
           
           
            return workspace;
        
    }
    
    
}
